package org.mountainpunch.ds.sparsematrix;

/**
 * An implementation of Sparse Matrix iterator.
 * @author siddharth
 */
final class SparseMatrixIteratorImpl<T> implements SparseMatrixIterator {
  private int _idx = -1;
  private MatrixEntry<T>[] _terms ;

  public SparseMatrixIteratorImpl(MatrixEntry<T>[] matrixTerms) {
    _terms = matrixTerms;
  }

  @Override
  public boolean hasNext() {
    return _idx < _terms.length - 1;
  }

  @Override
  public T next() {
    return _terms[++_idx].getValue();
  }

  @Override
  public void remove() {
    return;
  }

  @Override
  public int getRow() {
    return _terms[_idx].getRow();
  }

  @Override
  public int getCol() {
    return _terms[_idx].getCol();
  }

  @Override
  public T current() {
    return _terms[_idx].getValue() ;
  }

  @Override
  public T lastElement() {
    return (T) _terms[_terms.length - 1].getValue() ;
  }
}
